package com.atguigu.gmall.product.controller;


import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseTrademark;
import com.atguigu.gmall.product.service.BaseTrademarkService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

///admin/product/baseTrademark/{page}/{limit}
@RequestMapping("/admin/product")
@RestController
public class BaseTrademarkController {


    @Autowired
    BaseTrademarkService baseTrademarkService;


    /**
     * 品牌分页查询
     * @param page
     * @param limit
     * @return
     */
    @GetMapping("/baseTrademark/{page}/{limit}")
    public Result getBaseTrademark(@PathVariable("page") long page,
                                   @PathVariable("limit") long limit){

        //long current, long size
        Page<BaseTrademark> trademarkPage = new Page<>(page,limit);

        Page<BaseTrademark> result = baseTrademarkService.page(trademarkPage);
        return Result.ok(result);
    }


    ///admin/product/baseTrademark/save

    /**
     * 保存品牌
     * @param baseTrademark
     * @return
     */
    @PostMapping("/baseTrademark/save")
    public Result saveBaseTrademark(@RequestBody BaseTrademark baseTrademark){

        baseTrademarkService.save(baseTrademark);
        return Result.ok();
    }


    ///admin/product/baseTrademark/update

    /**
     * 修改品牌
     * @param baseTrademark
     * @return
     */
    @PutMapping("/baseTrademark/update")
    public Result updateBaseTrademark(@RequestBody BaseTrademark baseTrademark){

        baseTrademarkService.updateById(baseTrademark);
        return Result.ok();
    }



    ///admin/product/baseTrademark/remove/{id}

    /**
     * 品牌的删除
     * @param id
     * @return
     */
    @DeleteMapping("/baseTrademark/remove/{id}")
    public Result deleteBaseTrademark(@PathVariable("id") Long id){
        baseTrademarkService.removeById(id);
        return Result.ok();
    }

    // /admin/product/baseTrademark/get/{id}
    @GetMapping("/baseTrademark/get/{id}")
    public Result<BaseTrademark> getbaseTrademark(@PathVariable("id")Long id){
        BaseTrademark trademark = baseTrademarkService.getById(id);
        return Result.ok(trademark);
    }

}
